package AlienArena::ServerFactory;
use 5.006;
use lib '..';
use AlienArena::Server;
use AlienArena::RCon::Console;
use Carp qw(carp croak);
use strict;
use warnings;
our $VERSION = '0.01';
use lib '..';

sub new {
    my $class = shift;
    my $self = bless {}, $class;
}

sub create_server {
    my $self = shift;
    my ($host, $port, $pass) = @_;
    my $console = AlienArena::RCon::Console->new();
    my $server = AlienArena::Server->new($console);
    $server->_properties->_ip($host);
    $server->_properties->_port($port);
    $server->_properties->_pass($pass);
    return $server;
}

sub create_server_and_init {
    my $self = shift;
    my $server = $self->create_server(@_);
    unless ($server->init_console) {
	carp 'Server did not connect';
    }
    $server->update_runstate;
    return $server;
}

sub create_server_no_console {
    my $self = shift;
    return AlienArena::Server->new();
}

=head1 NAME

AlienArena::Server - Models an Alien Arena server

=head1 SYNOPSIS

    use AlienArena::ServerFactory;

    $server = AlienArena::ServerFactory->create_server('127.0.0.1','27901','s3kr1t');
    $server = AlienArena::ServerFactory->create_server_and_init('127.0.0.1','27901','s3kr1t');
    $server = AlienArena::ServerFactory->create_server_no_console();

=head1 METHODS

=head2 create_server($host, $port, $pass)

=head2 create_server_and_init($host, $port, $pass)

=head2 create_server_no_console

=head1 AUTHOR

Mark A. Jensen, C<< <maj -at- fortinbras -dot- us> >>


=head1 LICENSE AND COPYRIGHT

Copyright 2012 Mark A. Jensen.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut

1; # End of AlienArena::Server
